from django.db.models import Count
from django.http import JsonResponse
from django.views import View
from app.models import *
from app.url import *


# 我喜欢||我的关注的渲染

class MyLikeView(View):
    def get(self, request):

        user_id = request.GET.get('id', 'c61a8166-6a49-42ba-8173-39babe2c8d8f')
        ls = UserAttentions.objects.filter(own_user=user_id)
        list = []
        datalist = []
        for i in ls:
            list.append({
                'own_user': i.user_id,
            })
        for item in list:
            items = item.get('own_user')
            userInfo = User.objects.filter(id=items).values()
            for jitem in userInfo:
                print(jitem['userinfo_id'])
                userprofile = UserProfile.objects.filter(id=jitem['userinfo_id']).values()
                for jto in userprofile:
                    if jto['gender'] == 'M':
                        gender = '女'
                    else:
                        gender = '男'
                    datalist.append({
                        'id': jto['id'],
                        'avatar': jto['avatar'],
                        'age': jto['age'],
                        'height': jto['height'],
                        'education': jto['education'],
                        'gender': gender,
                        'nickname': jto['nickname'],
                        'my_city': jto['location'],
                    })
        return JsonResponse({
            'code': 200,
            "data": {
                "result": datalist,
            }
        })


# 喜欢我的数据
class LikeMe(View):
    def get(self, request):
        user_id = request.GET.get('id', 'c61a8166-6a49-42ba-8173-39babe2c8d8f')
        ls = UserAttentions.objects.filter(user_id=user_id)

        list = []
        datalist = []
        for i in ls:
            list.append({
                'own_user': i.own_user,
            })
        for item in list:
            items = item.get('own_user')
            userInfo = User.objects.filter(id=items).values()
            print(userInfo)
            for jitem in userInfo:
                userprofile = UserProfile.objects.filter(id=jitem['userinfo_id']).values()
                for jto in userprofile:
                    if jto['gender'] == 'M':
                        gender = '女'
                    else:
                        gender = '男'
                    datalist.append({
                        'id': jto['id'],
                        'avatar': jto['avatar'],
                        'age': jto['age'],
                        'height': jto['height'],
                        'education': jto['education'],
                        'gender': gender,
                        'nickname': jto['nickname'],
                        'my_city': jto['location'],

                    })
        return JsonResponse({
            'code': 200,
            'ls': datalist
        })
